package com.marco.ipdata.service.impl;

import com.marco.ipdata.dao.ChinaIPDao;
import com.marco.ipdata.domain.ChinaIP;
import com.marco.ipdata.service.ChinaIPService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * ChinaIPServiceImpl.java
 * Create on 2017/3/27
 * Copyright(c) JD Inc 2017. All Rights Reserved.
 * <pre>
 * 功能说明：
 * </pre>
 */
@Service
@Transactional
public class ChinaIPServiceImpl implements ChinaIPService {
    private static final Logger logger = LoggerFactory.getLogger(ChinaIPServiceImpl.class);
    private static final Integer PAGE_NUM = 500;
    @Autowired
    private ChinaIPDao ipDao;

    @Override
    public List<String> getIPListByFilters(Integer startIndex) {
        try {
            return ipDao.getIPsByLimit(startIndex, PAGE_NUM);
        } catch (Exception e) {
            throw new RuntimeException("查询IP出现异常", e);
        }
    }

    @Override
    public Integer totalCounts() {
        try {
            return ipDao.totalCounts();
        } catch (Exception e) {
            throw new RuntimeException("获取最新中国IP总数出现异常", e);
        }
    }

    @Override
    public void batchSave(List<ChinaIP> list) {
        try {
            ipDao.batchSave(list);
        } catch (Exception e) {
            throw new RuntimeException("保存出现异常", e);
        }
    }
}
